import { WS_MTYPES } from './TYPES'
import _EB from '../eventbus'

class WsController {
    [WS_MTYPES.CHAT_MSG](data) {
        // 根据消息类型
        console.log('chat-message', data)
        _EB.emit('_CHAT_MSG', data)
    }
    [WS_MTYPES.ATTENTION_MSG](data) {
        // 根据消息类型
        switch (data.data.action) {
            case 'log':
                console.log(`%c${data.from}`, "color: #fff; background: #a1a1a1;border-radius:4px;padding:0 4px ; font-size: 12px;", data.data.text)
                break;
            case 'modify-uinfo-succ':
                _EB.emit('_CHANGE_UINFO_SUCC', data)
                console.log(`%c${data.from}`, "color: #fff; background: #a1a1a1;border-radius:4px;padding:0 4px ; font-size: 12px;", data.data.text)
                break;
        }

    }
}

const controller = new WsController

function formatter(message) {
    console.log('message', message)
    try {
        // 我觉得你是个object
        message = JSON.parse(message)
        const strategy = controller[message.type]

        strategy(message)

    } catch (e) {
        // 不管了先
    }
}

export default formatter